package com.liang.util;

import java.util.List;

/**
 * 基于Hibernate分页处理
 * 
 * @author pjt
 * 
 * @param <Model>
 *            要显示的模型
 */
public class Page<Model> {

	/**
	 * 当前页显示的结果集
	 */
	private List<Model> list;
	
	/**
	 * 每页显示 记录数
	 */
	private int pageSize = 10;

	/**
	 * 当前是第几页
	 */
	private int currPage = 1;

	/**
	 * 所有结果集数量
	 */
	private int totalCount;

	public Page() {

	}

	public Page(List<Model>list,int currPage,int pageSize,int totalCount) {
		this.currPage = currPage;
		this.pageSize = pageSize;
		this.totalCount =  totalCount;
		this.list = list;
	}

	public List<Model> getList() {
		return list;
	}

	public void setList(List<Model> list) {
		this.list = list;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getCurrPage() {
		return currPage;
	}

	public void setCurrPage(int currPage) {
		this.currPage = currPage;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	/**
	 * @return 返回总页数
	 * @throws Exception
	 */
	public int getCountPage() {

		if (totalCount <= 0)
			return 0;

		return (totalCount + pageSize - 1) / pageSize;
	}

	/**
	 * @return 是否有下页
	 */
	public boolean isNextPage() {

		boolean result = false;

		try {

			int countPage = getCountPage();

			result = countPage > currPage;

		} catch (Exception e) {

		}
		return result;
	}

	/**
	 * @return 返回是否有下一页(兼容Struts标签)
	 */
	public boolean getNextPage() {
		return isNextPage();
	}

	/**
	 * @return 判断是否有前一页
	 */
	public boolean isPrePage() {
		return currPage > 1;
	}

	/**
	 * @return 返回是否有前一页(兼容Struts标签)
	 */
	public boolean getPrePage() {
		return isPrePage();
	}

}
